package com.linglan.common.enums;

import com.linglan.common.constants.CommonConstants;

public enum RedisKey {

    /**
     *
     */
    CACHE_USER_REFRESH_TOKEN("cache_user_refresh_token", 15552000, true);
    RedisKey(String keyPrefix, Integer timeout, boolean shuffle) {
        this.keyPrefix = keyPrefix;
        this.timeout = timeout;
        this.shuffle = shuffle;
    }

    public String getCacheKey(String keyUnique) {
        if (this.shuffle) {
            return String.join(CommonConstants.COLON, keyUnique, keyPrefix);
        } else {
            return String.join(CommonConstants.COLON, keyPrefix, keyUnique);
        }
    }

    public Integer getTimeout() {
        return timeout;
    }

    /**
     * key的修饰
     */
    private String keyPrefix;
    /**
     * 超时时间
     */
    private Integer timeout;
    /**
     * 乱序存储,  以防redis集群数据集中存储
     */
    private boolean shuffle;
}
